dsa

Java JDK, JRE and JVM

In this tutorial, you will learn about JDK, JRE, and JVM. You will also learn the key differences between them.



What is JVM?

JVM (Java Virtual Machine)is a virtual machine that enables a computer to run Java programs as well as programs written in other languages that are also compiled to Java bytecode.


Here is how JVM works:

First, Java code is complied into bytecode. This bytecode gets interpreted on different machines Between host system and Java source, Bytecode is an intermediary language.JVM is responsible for allocating memory space.


The JVM is detailed by a specification that formally describes what is required in a JVM implementation. Having a specification ensures interoperability of Java programs across different implementations so that program authors using the Java Development Kit (JDK) need not worry about idiosyncrasies of the underlying hardware platform.


How does Java program work?
Working of Java Program

So, now we understood that the primary function of JVM is to execute the byte code produced by compiler. Each operating system has different JVM, however the output they produce after execution of byte code is same across all operating systems. Which means that the byte code generated on Windows can be run on Mac OS and vice versa. That is why we call java as platform independent language.



What is JRE?

JRE (Java Runtime Environment) is a software package that provides Java class libraries, Java Virtual Machine (JVM), and other components that are required to run Java applications.


Java Run-time Environment (JRE) is the part of the Java Development Kit (JDK). It is a freely available software distribution which has Java Class Library, specific tools, and a stand-alone JVM. It is the most common environment available on devices to run java programs. The source Java code gets compiled and converted to Java bytecode. If you wish to run this bytecode on any platform, you require JRE. The JRE loads classes, verify access to memory, and retrieves the system resources. JRE acts as a layer on the top of the operating system.

JRE contains JVM and other Java class libraries.
Java Runtime Environment

If you need to run Java programs, but not develop them, JRE is what you need. You can download JRE from Java SE Runtime Environment 8 Downloads page.



What is JDK?

JDK (Java Development Kit) is a software development kit required to develop and execute(run) the Java program. When you download JDK, JRE is also downloaded with it.

The Java Development Kit (JDK) is a software development environment used for developing Java applications and applets. It includes the Java Runtime Environment (JRE), an interpreter/loader (Java), a compiler (javac), an archiver (jar), a documentation generator (Javadoc) and other tools needed in Java development

JDK is a kit(or package) which includes two things:

Development Tools(to provide an environment to develop your java programs)
JRE (to execute your java program).

JDK contains JRE and other tools to develop Java applications.
Java Development Kit

In addition to JRE, JDK also contains a number of development tools (compilers, JavaDoc, Java Debugger, etc).

If you want to develop Java applications, download JDK .



Relationship between JVM, JRE, and JDK.

JDK - Java Development Kit (in short JDK) is Kit which provides the environment to develop and execute(run) the Java program. JDK is a kit(or package) which includes two things:

JRE - Java Runtime Environment (to say JRE) is an installation package which provides environment to only run(not develop) the java program(or application)onto your machine. JRE is only used by them who only wants to run the Java Programs i.e. end users of your system.
JVM - Java Virtual machine(JVM) is a very important part of both JDK and JRE because it is contained or inbuilt in both. Whatever Java program you run using JRE or JDK goes into JVM and JVM is responsible for executing the java program line by line hence it is also known as interpreter.

JRE contains JVM and class libraries and JDK contains JRE, compilers, debuggers, and JavaDoc
Relationship between JVM, JRE, and JDK